package net.dreamlu.qa.controller;

import net.dreamlu.qa.model.Answer;
import net.dreamlu.qa.model.Question;
import net.dreamlu.qa.model.User;
import net.dreamlu.qa.validator.QuestionValidator;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

/**
 * 问题控制器
 * @author chunmeng.lu
 *
 */
public class QuestionController extends Controller {
	
	/**
	 *  提出新问题
	 */
	@Before(QuestionValidator.class)
	public void post() {
		User user = getSessionAttr("user");
		Question question = getModel(Question.class);
		question.set("user_id", user.get("id"));
		question.addQuestion(question);
		redirect("index", true);
	}
	
	/**
	 * 回答
	 */
	public void answer (){
		Answer answer = getModel(Answer.class);
		answer.addAnswer(answer);
		render("/solution/question.jsp");
	}
}
